package love.contact.database;

import wwk.common.sqlite.SqliteUtil;

/**
 * @author wangweike
 * @create_date 2011-12-22 9:45:47
 * @update_date 2011-12-22 9:45:47
 * 
 * groupId ʾ�� 1-1-1
 */

public class DatabaseManager
{
	//private String DatabaseName="ilovecontact_database.db";
	private String ContactGroupTable="contact_group";
	private String CreateTableGroup="create table IF NOT EXISTS groups (id varchar(10) primary key, name varchar(50))";
	private String InsertTableGroupFormat="insert into groups (id,name) values('%s','%s')";
	private String InsertTableContactGroupFormat="insert into "+ContactGroupTable+" (contactItemId,groupId) values('%s','%s')";
	private String UpdateGroupNameSqlFormat="update groups set name='%s' where id='%s'";
	
	private SqliteUtil sqliteUtil;
	
	public DatabaseManager()
	{
		sqliteUtil=new SqliteUtil();
	}
	
	public boolean addGroup(String groupName,String parentId)
	{
		String groupId=parentId;
		String sql=String.format(InsertTableGroupFormat,groupId,groupName);
		return sqliteUtil.executeSql(sql); 
	}
	
	public void addContactGroup(int contactId,String groupId)
	{
		String sql=String.format(InsertTableContactGroupFormat, contactId,groupId);
		sqliteUtil.executeSql(sql); 
	}
}
